<template>
  <div class="box">
    <!-- 头部 -->
    <div class="header-container">
      <div class="topic">添加企业</div>

      <div style="margin-top: 15px; margin-right: 10px">
        <el-button type="text" style="color: #4b5563">返回</el-button>
      </div>
    </div>
    <!-- 选择框 -->
    <div class="choice">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm">
        <!-- 顶部两个下拉选择框 -->
        <div class="form">
          <el-form-item label="企业名称" prop="ename" style="margin-right: 60px">
            <el-input v-model="ruleForm.ename" placeholder="请输入企业名称" style="width: 664px"></el-input>
          </el-form-item>
          <el-form-item label="企业地址" prop="address">
            <el-input v-model="ruleForm.address" placeholder="请输入企业地址" style="width: 664px"></el-input>
          </el-form-item>
        </div>
        <div class="form">
          <el-form-item label="企业电话" prop="phone">
            <el-input v-model="ruleForm.phone" placeholder="请输入企业电话" style="width: 664px"></el-input>
          </el-form-item>
          <el-form-item label="企业邮箱 " prop="email">
            <el-input v-model="ruleForm.email" placeholder="请输入企业邮箱" style="width: 664px"></el-input>
          </el-form-item>
        </div>
        <div class="form">
          <!-- <el-form-item label="所属行业" prop="type">
            <el-input v-model="ruleForm.type" placeholder="请输入所属行业" style="width: 664px"></el-input>
          </el-form-item> -->
          <div>
            <div style="color: rgb(96, 98, 102); font-size: 12px;">行业类型</div>
            <el-select v-model="ruleForm.type" placeholder="请选择行业类型" label="活动区域">
              <el-option v-for="(item, index ) in type" :label="item.name" :value="item.name"></el-option>
            </el-select>
          </div>
          <!-- <div class="formupload">
            图片上传
            <el-upload class="upload-demo" :on-preview="handlePreview" :on-remove="handleRemove"
              :on-success="handleSuccess" ref="upload" action="http://10.2.4.21:8088/back/enterprise/uploadenteimg"
              :before-remove="beforeRemove" multiple :limit="3" :on-exceed="handleExceed" :file-list="fileList">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">
                只能上传jpg/png文件，且不超过500kb
              </div>
            </el-upload>
          </div> -->
        </div>
        <!-- 文本域 -->
        <el-form-item label="企业宗旨" prop="introduction">
          <el-input type="textarea" placeholder="请输入企业宗旨" maxlength="600" :autosize="{ minRows: 4, maxRows: 6 }"
            v-model="ruleForm.introduction" show-word-limit></el-input>
        </el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm', ruleForm)">保存</el-button>
        <el-button @click="Jubpage">取消</el-button>
      </el-form>
      <!-- 取消与确定按钮 -->
    </div>
  </div>
</template>

<script>
import { handleAdd, handleType } from "@/api/enterprise/index";
export default {
  data() {
    return {
      type: [],
      fileList: [{}],
      ruleForm: {
        ename: "",
        address: "",
        type: "",
        email: "",
        url: "",
        introduction: "",
      },
      rules: {
        ename: [{ required: true, message: "请输入企业名称", trigger: "blur" }],
        address: [
          { required: true, message: "请输入企业地址", trigger: "blur" },
        ],
        phone: [
          { required: true, message: "请输入企业手机号", trigger: "blur" },
        ],
        type: [{ required: true, message: "请输入所属企业", trigger: "blur" }],
        study: [{ required: true, message: "请选择学历", trigger: "blur" }],
        enterprise: [
          { required: true, message: "请输入企业类型", trigger: "blur" },
        ],
        email: [
          {
            validator: (rule, value, callback) => {
              if (!value) {
                callback(new Error("请输入邮箱地址"));
              } else if (
                !/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value)
              ) {
                callback(new Error("请输入正确的邮箱地址"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
        introduction: [
          { required: true, message: "请输入职位描述", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {
    handleType().then(res => {
      this.type = res.data
      console.log(this.type, 'sdafhusd')
    })
  },
  methods: {
    handleSuccess(res) {
      console.log(res, "图片请求成功过");
      this.ruleForm.url = res.data;
    },
    submitForm(formName, e) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(e);
          handleAdd(e)
            .then((res) => {
              this.$message({
                message: "添加信息成功",
                type: "success",
              });
              this.$router.push("/enterprise");
            })
            .catch((error) => {
              console.log(error);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    Jubpage() {
      this.$router.push("/enterprise");
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  padding: 32px;
}

.header-container {
  box-sizing: border-box;
  width: 100%;
  height: 49px;
  border-bottom: 1px solid black;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;

  .topic {
    //字体样式
    font-size: 24px;
    font-weight: 700;
  }
}

.choice {
  width: 100%;
  display: flex;
}

.form {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;

  .formupload {
    width: 50%;
    padding: 10px 40px;
    box-sizing: border-box;
  }
}

.line {
  margin-left: 10px;
}
</style>